#include "login.h"
#include "ui_login.h"
#include "enroll.h"
#include "mainwindow.h"
#include <QString>
#include <QMessageBox>
#include <QMovie>
#include <QWidget>
#include <QRandomGenerator>
#include <QTimer>
#include "interface_control.h"


Login::Login(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Login)
    ,ID("")
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::SplashScreen|Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint);

    Interface_Control::getControlptr()->set_m_login(this);

    QMovie *mv=new QMovie(":/res/111.png"); //创建一个图
        ui->label->setMovie(mv); //将图插入标签
        mv->start(); //启动图
        ui->label->setScaledContents(true); //让图自适应标签大小

    QMovie *Mv=new QMovie(":/res/012.png");
        ui->label_3->setMovie(Mv);
        Mv->start();
        ui->label_3->setScaledContents(true);

}

Login::~Login()
{
    delete ui;

}


void Login::on_login_clicked()
{

    //为登录操作填写json文件
    QJsonObject js;
    js.insert("cmd",1);
    js.insert("loginid",ui->username->text());
    js.insert("password",ui->password->text());

    //发送消息
    Client_connet::Get_Connet()->set_obj(js);
    Client_connet::Get_Connet()->SendServer();

}



void Login::on_exit_clicked() //关闭
{
    this->close();
}


void Login::on_enroll_clicked()
{
    Interface_Control::getControlptr()->showm_enr();
    Interface_Control::getControlptr()->hideLogin();
}



void Login::mousePressEvent(QMouseEvent *event)
{
    isPressedWidget = true; // 当前鼠标按下的即是QWidget而非界面上布局的其它控件
    last = event->globalPos();
}

void Login::mouseMoveEvent(QMouseEvent *event)
{
    if (isPressedWidget)
        {
            int dx = event->globalX() - last.x();
            int dy = event->globalY() - last.y();
            last = event->globalPos();
            move(x()+dx, y()+dy);
        }
}

void Login::mouseReleaseEvent(QMouseEvent *event)
{
    int dx = event->globalX() - last.x();
    int dy = event->globalY() - last.y();
    move(x()+dx, y()+dy);
    isPressedWidget = false; // 鼠标松开时，置为false

}

//id显示
void Login::showID()
{
    ui->username->setText(ID);
}





